package com.ds;

import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * Created by IntelliJ IDEA.
 * User: daniel
 * Date: 01/11/2009
 * Time: 09:39:16
 */
public class RSSTrayIcon {

    private Trayable parent;


    public RSSTrayIcon(Trayable parent) {
        this.parent = parent;
        init();
    }

    private void init() {
        try {
            TrayIcon icon = new TrayIcon(parent.getTrayIcon(), parent.getTitle(), null);
            icon.addMouseListener(new MouseAdapter(){
                public void mouseClicked(MouseEvent e) {
                    super.mouseClicked(e);
                    if(e.getButton() == MouseEvent.BUTTON1){
                        //left click - toggle visible
                        parent.iconClicked();
                    } else if(e.getButton() == MouseEvent.BUTTON3) {
                        //right click - exit
                        System.exit(0);
                    }
                }
            });
            SystemTray.getSystemTray().add(icon);
        } catch (AWTException e) {
            e.printStackTrace();
        }
    }

    
}
